package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.annotation.SaveOplog;
import com.bifang.engine.assistant.core.enums.AuTypeEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.util.ApplicationContextHelper;
import com.bifang.module.base.core.helper.ApiContainer;
import com.bifang.module.base.core.helper.ApiModel;
import com.bifang.module.base.core.helper.DictHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.enums.*;
import com.jwsoft.manager.common.vo.common.AreaControlVO;
import com.jwsoft.manager.common.vo.eduJhjySync.EduJhjySyncKeyVO;
import com.jwsoft.manager.common.vo.eduJhjySync.EduJhjySyncQueryVO;
import com.jwsoft.manager.common.vo.eduJhjySync.EduJhjySyncVO;
import com.jwsoft.manager.common.vo.eduStudentEnroll.EduStudentEnrollQueryVO;
import com.jwsoft.manager.common.vo.eduSystemConfig.EduSystemConfigFuncQueryVO;
import com.jwsoft.manager.core.dao.model.EduJhjySync;
import com.jwsoft.manager.core.dao.model.EduStudentEnroll;
import com.jwsoft.manager.core.dao.service.EduJhjySyncService;
import com.jwsoft.manager.core.dao.service.EduStudentEnrollService;
import com.jwsoft.manager.core.integration.EduJhjySyncIntegration;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import com.jwsoft.manager.core.util.EduHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
/**
 * 金华教育同步业务实现类
 *
 * @author wangtao
 * @since 2023-03-16
 */
@ApiService(funcCode = "eduJhjySync", title = "金华教育同步")
public class EduJhjySyncIntegrationImpl implements EduJhjySyncIntegration {

    @Autowired
    public EduJhjySyncService eduJhjySyncService;

    @Autowired
    private EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    private EduStudentEnrollService eduStudentEnrollService;

    @Autowired
    private ApiContainer apiContainer;
    @Autowired
    private EduHelper eduHelper;

    @Autowired
    private DictHelper dictHelper;

    @Override
    @OpApi(funcCode = "eduJhjySync0001", title = "金华教育同步分页查询", funcType = FuncTypeEnum.query)
    public PageInfo<EduJhjySyncVO> getList(EduJhjySyncQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(1000);
        }

        if (ObjectUtils.isEmpty(vo.getYear())){
            throw new AppException("招生年度不能未空！");
        }

        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        if (ObjectUtils.isEmpty(vo.getYear())){
            eduHelper.thisYear();
        }
        QueryWrapper<EduJhjySync> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(EduJhjySync::getYear,vo.getYear())
                .eq(!StringUtils.isBlank(vo.getIdcard()),EduJhjySync::getIdcard,vo.getIdcard())
                .eq(!StringUtils.isBlank(vo.getLqFlag()),EduJhjySync::getLqFlag,vo.getLqFlag())
                .eq(!ObjectUtils.isEmpty(vo.getEduStage()),EduJhjySync::getEduStage,vo.getEduStage())
                .eq(!ObjectUtils.isEmpty(vo.getSchoolType()),EduJhjySync::getSchoolType,vo.getSchoolType())
                .eq(!ObjectUtils.isEmpty(vo.getBmSyncFlag()),EduJhjySync::getBmSyncFlag,vo.getBmSyncFlag())
                .eq(!ObjectUtils.isEmpty(vo.getQxlqSyncFlag()),EduJhjySync::getBmSyncFlag,vo.getQxlqSyncFlag())
                .eq(!ObjectUtils.isEmpty(vo.getLqSyncFlag()),EduJhjySync::getLqSyncFlag,vo.getLqSyncFlag())
                .eq(!ObjectUtils.isEmpty(vo.getDeleteSyncFlag()),EduJhjySync::getDeleteSyncFlag,vo.getDeleteSyncFlag());
        List<EduJhjySync> list = eduJhjySyncService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduJhjySync> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduJhjySyncVO> resultList = Convert.toList(EduJhjySyncVO.class, pageInfo.getList());
        // 转义数据字典值
         dictHelper.valueToName(resultList, Arrays.asList(EduJhjySyncEnum.values()));
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduJhjySync0002", title = "金华教育同步根据主键查询详情", funcType = FuncTypeEnum.query)
    public EduJhjySyncVO getById(EduJhjySyncKeyVO vo) {
        EduJhjySync entity = eduJhjySyncService.getById(vo.getJhjyId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("查询不到详细信息!");
        }
        EduJhjySyncVO result = Convert.convert(EduJhjySyncVO.class, entity);
        return result;
    }
    /** 保存前统一校验*/
    @Override
    @OpApi(funcCode = "eduJhjySync0003", title = "金华教育同步保存前校验", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE)
    public void checkSave(EduJhjySyncVO vo) {
        //主键为空为新增校验

        //主键不为空为修改校验
    }

    @Override
    @OpApi(funcCode = "eduJhjySync0004", title = "金华教育同步新增", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduJhjySync0004",
            operationName = "金华教育同步新增",
            dataType = "jhjyId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduJhjySyncVO add(EduJhjySyncVO vo) {
        //保存前校验
        checkSave(vo);
        //保存数据
        EduJhjySync entity = Convert.convert(EduJhjySync.class, vo);
        eduJhjySyncService.save(entity);
        //将主键设置回vo使操作日志可以取到
        vo.setJhjyId(entity.getJhjyId());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduJhjySync0005", title = "金华教育同步修改", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduJhjySync0005",
            operationName = "金华教育同步修改",
            dataType = "jhjyId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduJhjySyncVO edit(EduJhjySyncVO vo) {
        if (ObjectUtils.isEmpty(vo.getJhjyId())) {
            throw new AppException("传入需要修改的主键不能为空!");
        }
        EduJhjySync oldEntity = eduJhjySyncService.getById(vo.getJhjyId());
        if (ObjectUtils.isEmpty(oldEntity)) {
            throw new AppException("查询不到需要修改的信息!");
        }
        //保存前校验
        checkSave(vo);
        //保存数据
        EduJhjySync entity = Convert.convert(EduJhjySync.class, vo);
        eduJhjySyncService.updateById(entity);
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduJhjySync0006", title = "金华教育同步根据主键删除", funcType = FuncTypeEnum.delete)
    @SaveOplog(
            operationType = "eduJhjySync0006",
            operationName = "金华教育同步删除",
            dataType = "jhjyId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void del(EduJhjySyncKeyVO vo) {
        if (ObjectUtils.isEmpty(vo.getJhjyId())) {
            throw new AppException("传入需要删除的数据主键不能为空!");
        }
        EduJhjySync entity = eduJhjySyncService.getById(vo.getJhjyId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("未找到需要删除的信息!");
        }
        eduJhjySyncService.removeById(vo.getJhjyId());
    }

    @Override
    @OpApi(funcCode = "eduJhjySync0007", title = "金华教育同步删除报名数据", funcType = FuncTypeEnum.delete)
    public void saveQx(EduStudentEnrollQueryVO vo) {
        if (ObjectUtils.isEmpty(vo.getStudentEnrollId())){
            throw new AppException("学生报名主键不能未空");
        }
        EduStudentEnroll eduStudentEnroll = null;
        if (StringUtils.isNotBlank(vo.getStudentEnrollId())) {
            eduStudentEnroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
            if (eduStudentEnroll == null) {
                throw new AppException("系统中未找到报名数据");
            }
        }
        saveQx(eduStudentEnroll);
    }


    @Override
    @OpApi(funcCode = "eduJhjySync0008", title = "金华教育报名数据单个同步", funcType = FuncTypeEnum.update)
    @Transactional
    public void jhJyBmSync(EduJhjySyncVO vo) {
        if (StringUtils.isBlank(vo.getJhjyId())) {
            throw new AppException("金华教育同步主键不能为空");
        }
        EduJhjySync eduJhjySync = eduJhjySyncService.getById(vo.getJhjyId());
        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        queryVO.setAreaCode(eduJhjySync.getAreaCode());
        queryVO.setEduConfigKey("unifiedSupervisionEnrollAdd");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (apiModel == null) {
            throw new AppException(eduJhjySync.getAreaCode() + "未找到处理报名保存的个性化方法");
        }
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                apiModel.getMethod().invoke(bean, eduJhjySync);
            } else {
                throw new AppException(vo.getAreaCode() + "未找到处理报名保存的个性化方法");
            }
            //更新金华教育同步表中的报名同步信息。
            UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
            updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                    .set(EduJhjySync::getBmSyncFlag, BoolEnum.TRUE.getType())
                    .set(EduJhjySync::getBmSyncRemark, "上传报名成功");
            eduJhjySyncService.update(updateWrapper);
        } catch (AppException e) {
            throw e;
        } catch (InvocationTargetException e) {
            try {
                AppException exception = (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(), e.getTargetException());
            } catch (Exception ex) {
                throw new AppException(e.getCause().getMessage(), e.getTargetException());
            }

        } catch (Exception e) {
            throw new AppException(e.getMessage(), e);
        }
    }

    @Override
    @OpApi(funcCode = "eduJhjySync0009", title = "金华教育取消录取单个同步", funcType = FuncTypeEnum.update)
    @Transactional
    public void jhJyQxlqSync(EduJhjySyncVO vo) {
        if (StringUtils.isBlank(vo.getJhjyId())) {
            throw new AppException("金华教育同步主键不能为空");
        }
        EduJhjySync eduJhjySync = eduJhjySyncService.getById(vo.getJhjyId());
        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        queryVO.setAreaCode(eduJhjySync.getAreaCode());
        queryVO.setEduConfigKey("unifiedSupervisionEnrollCancelAdmit");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (apiModel == null) {
            throw new AppException(eduJhjySync.getAreaCode() + "未找到处理取消录取个性化方法");
        }
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                apiModel.getMethod().invoke(bean, eduJhjySync);
                EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(eduJhjySync.getStudentEnrollId());
                ArrayList<String> enrollStatusList = new ArrayList<>();
                enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
                enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
                enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
                if (!enrollStatusList.contains(eduStudentEnroll.getEnrollStatus())){
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getLqFlag,BoolEnum.FALSE.getType())
                            .set(EduJhjySync::getLqSyncFlag,BoolEnum.FALSE.getType())
                            .set(EduJhjySync::getQxlqFlag,BoolEnum.TRUE.getType())
                            .set(EduJhjySync::getQxlqSyncFlag, BoolEnum.TRUE.getType())
                            .set(EduJhjySync::getQxlqSyncRemark, "取消录取同步成功");
                    eduJhjySyncService.update(updateWrapper);
                }

            } else {
                throw new AppException(vo.getAreaCode() + "未找到处理取消录取的个性化方法");
            }
        }catch (AppException e) {
            throw e;
        } catch (InvocationTargetException e) {
            try {
                AppException exception = (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(), e.getTargetException());
            } catch (Exception ex) {
                throw new AppException(e.getCause().getMessage(), e.getTargetException());
            }

        } catch (Exception e) {
            throw new AppException(e.getMessage(), e);
        }
    }

    @Override
    @OpApi(funcCode = "eduJhjySync0010", title = "金华教育录取单个同步", funcType = FuncTypeEnum.update)
    @Transactional
    public void jhJylqSync(EduJhjySyncVO vo) {
        if (StringUtils.isBlank(vo.getJhjyId())) {
            throw new AppException("金华教育同步主键不能为空");
        }
        EduJhjySync eduJhjySync = eduJhjySyncService.getById(vo.getJhjyId());
        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        queryVO.setAreaCode(eduJhjySync.getAreaCode());
        queryVO.setEduConfigKey("unifiedSupervisionEnrollAdmit");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (apiModel == null) {
            throw new AppException(eduJhjySync.getAreaCode() + "未找到处理取消录取个性化方法");
        }
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                apiModel.getMethod().invoke(bean, eduJhjySync);
                EduStudentEnroll eduStudentEnroll = eduStudentEnrollService.getById(eduJhjySync.getStudentEnrollId());
                if (EnrollStatusFormalEnum.lq.getType().equals(eduStudentEnroll.getEnrollStatus())){
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    //将同步数据表中的录取信息进行修改
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getLqSyncFlag, BoolEnum.TRUE.getType())
                            .set(EduJhjySync::getLqSyncRemark, "录取同步成功")
                            .set(EduJhjySync::getLqFlag,BoolEnum.TRUE.getType())
                            .set(EduJhjySync::getQxlqFlag,BoolEnum.FALSE.getType())
                            .set(EduJhjySync::getQxlqSyncFlag,BoolEnum.FALSE.getType());
                    eduJhjySyncService.update(updateWrapper);
                }
            } else {
                throw new AppException(vo.getAreaCode() + "未找到处理录取的个性化方法");
            }
        }catch (AppException e) {
            throw e;
        } catch (InvocationTargetException e) {
            try {
                AppException exception = (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(), e.getTargetException());
            } catch (Exception ex) {
                throw new AppException(e.getCause().getMessage(), e.getTargetException());
            }

        } catch (Exception e) {
            throw new AppException(e.getMessage(), e);
        }
    }


    @Override
    public void saveLq(EduStudentEnroll eduStudentEnroll) {
        EduJhjySync eduJhjySync=saveBm(eduStudentEnroll);

        if(BoolEnum.TRUE.getType().equals(eduStudentEnroll.getAdmitFlag())){
            if(eduJhjySync.getLqFlag().equals(BoolEnum.TRUE.getType())&&eduJhjySync.getLqSyncFlag().equals(BoolEnum.TRUE.getType())){
                //已录取上传，不做处理
                return;
            }
            //录取
            eduJhjySync.setSchoolName(eduStudentEnroll.getSchoolName());
            eduJhjySync.setLqFlag(BoolEnum.TRUE.getType());
            if(BoolEnum.TRUE.getType().equals(eduJhjySync.getBmSyncFlag())){
                //jhjyIntegration.unifiedSupervisionEnrollAdmit(eduJhjySync);
                eduJhjySync.setQxlqFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setQxlqSyncFlag(BoolEnum.FALSE.getType());
                try {
                    //jhjyIntegration.unifiedSupervisionEnrollAdmit(eduJhjySync);
                    EduSystemConfigFuncQueryVO queryVO=new EduSystemConfigFuncQueryVO();
                    if(StringUtils.isBlank(eduStudentEnroll.getAreaCode())){
                        eduStudentEnroll.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
                    }
                    queryVO.setAreaCode(eduStudentEnroll.getAreaCode());
                    queryVO.setEduConfigKey("unifiedSupervisionEnrollAdmit");
                    String funcCode=eduSystemConfigIntegration.getFuncCode(queryVO);
                    ApiModel apiModel=apiContainer.get(funcCode);
                    if(apiModel!=null){
                        try {
                            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                            if (null != bean) {
                                apiModel.getMethod().invoke(bean, eduJhjySync);
                            }else {
                                throw new AppException(eduStudentEnroll.getAreaCode()+"未找到处理报名保存的个性化方法");
                            }
                        }catch (AppException e ){
                            throw e;
                        }catch (InvocationTargetException e ){
                            try{
                                AppException exception= (AppException) e.getTargetException();
                                throw new AppException(exception.getMsg(),e.getTargetException());
                            }catch (Exception ex){
                                throw new AppException(e.getCause().getMessage(),e.getTargetException());
                            }

                        }catch (Exception e ){
                            throw new AppException( e.getMessage(),e);
                        }
                    }else {
                        throw new AppException(eduStudentEnroll.getAreaCode()+"未找到处理报名保存的个性化方法");
                    }
                    eduJhjySync.setLqSyncFlag("1");
                    eduJhjySync.setLqSyncRemark("录取上传成功");
                }catch (Exception e){
                    String msg=e.getMessage();
                    if(msg.length()>300){
                        msg=msg.substring(0,200);
                    }
                    eduJhjySync.setLqSyncFlag("2");
                    eduJhjySync.setLqSyncRemark(msg);
                }
                eduJhjySyncService.updateById(eduJhjySync);
            }
        }else{
            //不予录取
            if(BoolEnum.TRUE.getType().equals(eduJhjySync.getLqFlag())){
                if(BoolEnum.TRUE.getType().equals(eduJhjySync.getLqSyncFlag())){
                    if(eduJhjySync.getQxlqFlag().equals(BoolEnum.TRUE.getType())&&eduJhjySync.getQxlqSyncFlag().equals(BoolEnum.TRUE.getType())){
                        //取消录取已同步，不做处理
                        return;
                    }
                    eduJhjySync.setQxlqFlag(BoolEnum.TRUE.getType());
                    eduJhjySync.setQxlqSyncFlag(BoolEnum.FALSE.getType());
                    try {
                        EduSystemConfigFuncQueryVO queryVO=new EduSystemConfigFuncQueryVO();
                        if(StringUtils.isBlank(eduStudentEnroll.getAreaCode())){
                            eduStudentEnroll.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
                        }
                        queryVO.setAreaCode(eduStudentEnroll.getAreaCode());
                        queryVO.setEduConfigKey("unifiedSupervisionEnrollAdmit");
                        String funcCode=eduSystemConfigIntegration.getFuncCode(queryVO);
                        ApiModel apiModel=apiContainer.get(funcCode);
                        if(apiModel!=null){
                            try {
                                Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                                if (null != bean) {
                                    apiModel.getMethod().invoke(bean, eduJhjySync);
                                }else {
                                    throw new AppException(eduStudentEnroll.getAreaCode()+"未找到处理报名保存的个性化方法");
                                }
                            }catch (AppException e ){
                                throw e;
                            }catch (InvocationTargetException e ){
                                try{
                                    AppException exception= (AppException) e.getTargetException();
                                    throw new AppException(exception.getMsg(),e.getTargetException());
                                }catch (Exception ex){
                                    throw new AppException(e.getCause().getMessage(),e.getTargetException());
                                }

                            }catch (Exception e ){
                                throw new AppException( e.getMessage(),e);
                            }
                        }else {
                            throw new AppException(eduStudentEnroll.getAreaCode()+"未找到处理报名保存的个性化方法");
                        }
                        eduJhjySync.setQxlqSyncFlag("1");
                        eduJhjySync.setLqFlag("0");
                        eduJhjySync.setLqSyncFlag("0");
                        eduJhjySync.setQxlqSyncRemark("取消录取上传成功");
                    }catch (Exception e){
                        String msg=e.getMessage();
                        if(msg.length()>300){
                            msg=msg.substring(0,200);
                        }
                        eduJhjySync.setQxlqSyncFlag("2");
                        eduJhjySync.setQxlqSyncRemark(msg);
                    }
                }else{
                    eduJhjySync.setLqFlag(BoolEnum.FALSE.getType());
                    eduJhjySync.setLqSyncFlag("0");
                }
                eduJhjySyncService.updateById(eduJhjySync);
            }
        }

    }

    @Override
    public EduJhjySync saveBm(EduStudentEnroll eduStudentEnroll) {
        QueryWrapper<EduJhjySync> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(EduJhjySync::getYear,eduStudentEnroll.getYear())
                .eq(EduJhjySync::getIdcard,eduStudentEnroll.getIdcard())
                .eq(EduJhjySync::getAreaCode, eduStudentEnroll.getAreaCode())
                .eq(EduJhjySync::getDeleteSyncFlag,BoolEnum.FALSE.getType());
        List<EduJhjySync> eduJhjySyncList=eduJhjySyncService.list(queryWrapper);
        EduJhjySync eduJhjySync=null;
        if(!CollectionUtils.isEmpty(eduJhjySyncList)){
            eduJhjySync=eduJhjySyncList.get(0);
            eduJhjySync.setStudentEnrollId(eduStudentEnroll.getStudentEnrollId());
            eduJhjySync.setSchoolName(eduStudentEnroll.getSchoolName());
            eduJhjySync.setAreaCode(eduStudentEnroll.getAreaCode());
            if("1".equals(eduStudentEnroll.getSchoolNature())){
                eduJhjySync.setSchoolType(32);
            }else {
                eduJhjySync.setSchoolType(31);
            }
            if(BoolEnum.FALSE.getType().equals(eduJhjySync.getBmSyncFlag())){
                try {
                    EduSystemConfigFuncQueryVO queryVO=new EduSystemConfigFuncQueryVO();
                    if(StringUtils.isBlank(eduStudentEnroll.getAreaCode())){
                        eduStudentEnroll.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
                    }
                    queryVO.setAreaCode(eduStudentEnroll.getAreaCode());
                    queryVO.setEduConfigKey("unifiedSupervisionEnrollAdmit");
                    String funcCode=eduSystemConfigIntegration.getFuncCode(queryVO);
                    ApiModel apiModel=apiContainer.get(funcCode);
                    if(apiModel!=null){
                        try {
                            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                            if (null != bean) {
                                apiModel.getMethod().invoke(bean, eduJhjySync);
                            }else {
                                throw new AppException(eduStudentEnroll.getAreaCode()+"未找到处理报名保存的个性化方法");
                            }
                        }catch (AppException e ){
                            throw e;
                        }catch (InvocationTargetException e ){
                            try{
                                AppException exception= (AppException) e.getTargetException();
                                throw new AppException(exception.getMsg(),e.getTargetException());
                            }catch (Exception ex){
                                throw new AppException(e.getCause().getMessage(),e.getTargetException());
                            }

                        }catch (Exception e ){
                            throw new AppException( e.getMessage(),e);
                        }
                    }else {
                        throw new AppException(eduStudentEnroll.getAreaCode()+"未找到处理报名保存的个性化方法");
                    }
                    eduJhjySync.setBmSyncFlag("1");
                    eduJhjySync.setBmSyncRemark("报名上传成功");
                }catch (Exception e){
                    String msg=e.getMessage();
                    if(msg.length()>300){
                        msg=msg.substring(0,200);
                    }
                    eduJhjySync.setBmSyncFlag("2");
                    eduJhjySync.setBmSyncRemark(msg);
                }

                eduJhjySyncService.saveOrUpdate(eduJhjySync);
            }
            return eduJhjySync;
        }else{
            eduJhjySync=new EduJhjySync();
            eduJhjySync.setJhjyId(IdUtil.simpleUUID());
            eduJhjySync.setName(eduStudentEnroll.getFullName());
            eduJhjySync.setIdcard(eduStudentEnroll.getIdcard());
            eduJhjySync.setAreaCode(eduStudentEnroll.getAreaCode());
            eduJhjySync.setSex(StringUtils.isBlank(eduStudentEnroll.getSex())?1:Integer.valueOf(eduStudentEnroll.getSex()));
            eduJhjySync.setTel(StringUtils.isNotBlank(eduStudentEnroll.getFatherCellphone())?eduStudentEnroll.getFatherCellphone():eduStudentEnroll.getMotherCellphone());
            if("2".equals(eduStudentEnroll.getSchoolCategory())){
                eduJhjySync.setEduStage(13);
            }else if("3".equals(eduStudentEnroll.getSchoolCategory())){
                eduJhjySync.setEduStage(14);
            }
            if("1".equals(eduStudentEnroll.getSchoolNature())){
                eduJhjySync.setSchoolType(32);
            }else {
                eduJhjySync.setSchoolType(31);
            }
            eduJhjySync.setSchoolName(eduStudentEnroll.getSchoolName());
            eduJhjySync.setYear(eduStudentEnroll.getYear());
            eduJhjySync.setSubmitTime(DateUtil.formatDateTime(eduStudentEnroll.getCreateTime()));
            eduJhjySync.setStudentEnrollId(eduStudentEnroll.getStudentEnrollId());
            eduJhjySync.setBmSyncFlag(BoolEnum.FALSE.getType());
            eduJhjySync.setDeleteFlag(BoolEnum.FALSE.getType());
            eduJhjySync.setDeleteSyncFlag(BoolEnum.FALSE.getType());
            eduJhjySync.setLqFlag(BoolEnum.FALSE.getType());
            eduJhjySync.setLqSyncFlag(BoolEnum.FALSE.getType());
            eduJhjySync.setQxlqFlag(BoolEnum.FALSE.getType());
            eduJhjySync.setQxlqSyncFlag(BoolEnum.FALSE.getType());
            try {

                EduSystemConfigFuncQueryVO queryVO=new EduSystemConfigFuncQueryVO();
                if(StringUtils.isBlank(eduStudentEnroll.getAreaCode())){
                    eduStudentEnroll.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
                }
                queryVO.setAreaCode(eduStudentEnroll.getAreaCode());
                queryVO.setEduConfigKey("unifiedSupervisionEnrollAdd");
                String funcCode=eduSystemConfigIntegration.getFuncCode(queryVO);
                ApiModel apiModel=apiContainer.get(funcCode);
                if(apiModel!=null){
                    try {
                        Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                        if (null != bean) {
                            apiModel.getMethod().invoke(bean, eduJhjySync);
                        }else {
                            throw new AppException(eduStudentEnroll.getAreaCode()+"未找到处理报名保存的个性化方法");
                        }
                    }catch (AppException e ){
                        throw e;
                    }catch (InvocationTargetException e ){
                        try{
                            AppException exception= (AppException) e.getTargetException();
                            throw new AppException(exception.getMsg(),e.getTargetException());
                        }catch (Exception ex){
                            throw new AppException(e.getCause().getMessage(),e.getTargetException());
                        }

                    }catch (Exception e ){
                        throw new AppException( e.getMessage(),e);
                    }
                }else {
                    throw new AppException(eduStudentEnroll.getAreaCode()+"未找到处理报名保存的个性化方法");
                }


                eduJhjySync.setBmSyncFlag("1");
                eduJhjySync.setBmSyncRemark("报名上传成功");
            }catch (Exception e){
                String msg=e.getMessage();
                if(msg.length()>300){
                    msg=msg.substring(0,200);
                }
                eduJhjySync.setBmSyncFlag("2");
                eduJhjySync.setBmSyncRemark(msg);
            }

            eduJhjySyncService.saveOrUpdate(eduJhjySync);
        }
        return eduJhjySync;
    }

    @Override
    public void saveQx(EduStudentEnroll eduStudentEnroll) {
        QueryWrapper<EduJhjySync> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduJhjySync::getYear, eduStudentEnroll.getYear())
                .eq(EduJhjySync::getIdcard, eduStudentEnroll.getIdcard())
                .eq(EduJhjySync::getAreaCode, eduStudentEnroll.getAreaCode())
                .eq(EduJhjySync::getDeleteSyncFlag, BoolEnum.FALSE.getType());
        List<EduJhjySync> eduJhjySyncList = eduJhjySyncService.list(queryWrapper);
        if (CollectionUtils.isEmpty(eduJhjySyncList)) {
            return;
        }
        EduJhjySync eduJhjySync = eduJhjySyncList.get(0);
        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        if (StringUtils.isBlank(eduStudentEnroll.getAreaCode())) {
            eduStudentEnroll.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        queryVO.setAreaCode(eduStudentEnroll.getAreaCode());
        queryVO.setEduConfigKey("unifiedSupervisionEnrollDelete");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (BoolEnum.FALSE.getType().equals(eduJhjySync.getLqFlag()) && !BoolEnum.TRUE.getType().equals(eduJhjySync.getBmSyncFlag())) {
            if (SchoolNatureEnum.gb.getType().equals(eduStudentEnroll.getSchoolNature())) {
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getDeleteFlag, BoolEnum.TRUE.getType())
                        .set(EduJhjySync::getDeleteSyncRemark, "因报名和录取都未上传到金华，直接处理为删除报名");
                eduJhjySyncService.update(updateWrapper);

                try {
                    eduJhjySync.setDeleteFlag(BoolEnum.TRUE.getType());
                    eduJhjySync.setDeleteSyncFlag(BoolEnum.TRUE.getType());
                    eduJhjySync.setDeleteReason("取消");
                    if (apiModel != null) {
                        try {
                            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                            if (null != bean) {
                                apiModel.getMethod().invoke(bean, eduJhjySync);
                            } else {
                                throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                            }
                        } catch (AppException e) {
                            throw e;
                        } catch (InvocationTargetException e) {
                            try {
                                AppException exception = (AppException) e.getTargetException();
                                throw new AppException(exception.getMsg(), e.getTargetException());
                            } catch (Exception ex) {
                                throw new AppException(e.getCause().getMessage(), e.getTargetException());
                            }

                        } catch (Exception e) {
                            throw new AppException(e.getMessage(), e);
                        }
                    } else {
                        throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return;
        }
        if (BoolEnum.FALSE.getType().equals(eduJhjySync.getLqFlag())) {
            if ("0".equals(eduStudentEnroll.getSchoolNature())) {
                eduJhjySync.setDeleteFlag(BoolEnum.TRUE.getType());
                eduJhjySync.setDeleteSyncFlag(BoolEnum.TRUE.getType());
                eduJhjySync.setDeleteReason("取消");
                if (apiModel != null) {
                    try {
                        Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                        if (null != bean) {
                            apiModel.getMethod().invoke(bean, eduJhjySync);
                        } else {
                            throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                        }
                    } catch (AppException e) {
                        throw e;
                    } catch (InvocationTargetException e) {
                        try {
                            AppException exception = (AppException) e.getTargetException();
                            throw new AppException(exception.getMsg(), e.getTargetException());
                        } catch (Exception ex) {
                            throw new AppException(e.getCause().getMessage(), e.getTargetException());
                        }

                    } catch (Exception e) {
                        throw new AppException(e.getMessage(), e);
                    }
                } else {
                    throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                }
            } else {
                eduJhjySync.setLqFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setLqSyncFlag(BoolEnum.FALSE.getType());
            }
        }
        if (BoolEnum.TRUE.getType().equals(eduJhjySync.getLqFlag())) {
            if (BoolEnum.TRUE.getType().equals(eduJhjySync.getLqSyncFlag())) {
                eduJhjySync.setLqFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setLqSyncFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setQxlqFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setQxlqSyncFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setDeleteReason("取消");
                if (apiModel != null) {
                    try {
                        Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                        if (null != bean) {
                            apiModel.getMethod().invoke(bean, eduJhjySync);
                        } else {
                            throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                        }
                    } catch (AppException e) {
                        throw e;
                    } catch (InvocationTargetException e) {
                        try {
                            AppException exception = (AppException) e.getTargetException();
                            throw new AppException(exception.getMsg(), e.getTargetException());
                        } catch (Exception ex) {
                            throw new AppException(e.getCause().getMessage(), e.getTargetException());
                        }

                    } catch (Exception e) {
                        throw new AppException(e.getMessage(), e);
                    }
                } else {
                    throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                }
            } else {
                eduJhjySync.setLqFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setLqSyncFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setQxlqFlag(BoolEnum.FALSE.getType());
                eduJhjySync.setQxlqSyncFlag(BoolEnum.FALSE.getType());
                try {
                    if (apiModel != null) {
                        try {
                            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                            if (null != bean) {
                                apiModel.getMethod().invoke(bean, eduJhjySync);
                            } else {
                                throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                            }
                        } catch (AppException e) {
                            throw e;
                        } catch (InvocationTargetException e) {
                            try {
                                AppException exception = (AppException) e.getTargetException();
                                throw new AppException(exception.getMsg(), e.getTargetException());
                            } catch (Exception ex) {
                                throw new AppException(e.getCause().getMessage(), e.getTargetException());
                            }

                        } catch (Exception e) {
                            throw new AppException(e.getMessage(), e);
                        }
                    } else {
                        throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if ("0".equals(eduStudentEnroll.getSchoolNature())) {
                eduJhjySync.setDeleteFlag(BoolEnum.TRUE.getType());
                eduJhjySync.setDeleteSyncFlag(BoolEnum.TRUE.getType());
                eduJhjySync.setDeleteReason("取消");
                if (apiModel != null) {
                    try {
                        Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                        if (null != bean) {
                            apiModel.getMethod().invoke(bean, eduJhjySync);
                        } else {
                            throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                        }
                    } catch (AppException e) {
                        throw e;
                    } catch (InvocationTargetException e) {
                        try {
                            AppException exception = (AppException) e.getTargetException();
                            throw new AppException(exception.getMsg(), e.getTargetException());
                        } catch (Exception ex) {
                            throw new AppException(e.getCause().getMessage(), e.getTargetException());
                        }

                    } catch (Exception e) {
                        throw new AppException(e.getMessage(), e);
                    }
                } else {
                    throw new AppException(eduStudentEnroll.getAreaCode() + "未找到处理金华教育删除报名的个性化方法");
                }
            }
        }
        eduJhjySyncService.updateById(eduJhjySync);
    }

    @Override
    public int eduJhjyBmSync(AreaControlVO vo) {
        if (StringUtils.isBlank(vo.getAreaCode())) {
            throw new AppException("行政区划不能为空");
        }
        QueryWrapper<EduJhjySync> querySyncQueryWrapper = new QueryWrapper<>();
        int year = eduHelper.thisYear();
        querySyncQueryWrapper.lambda().eq(EduJhjySync::getBmSyncFlag, BoolEnum.FALSE.getType())
                .eq(EduJhjySync::getAreaCode, vo.getAreaCode())
                .eq(EduJhjySync::getYear, year);
        PageHelper.startPage(1, 10000);
        List<EduJhjySync> querySyncList = eduJhjySyncService.list(querySyncQueryWrapper);
        PageInfo<EduJhjySync> pageInfo = new PageInfo(querySyncList);
        if (CollectionUtils.isEmpty(querySyncList)) {
            return 0;
        }
        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setEduConfigKey("unifiedSupervisionEnrollAdd");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (apiModel == null) {
            throw new AppException(vo.getAreaCode() + "未找到处理报名保存的个性化方法");
        }
        for (EduJhjySync eduJhjySync : pageInfo.getList()) {
            try {
                Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                if (null != bean) {
                    apiModel.getMethod().invoke(bean, eduJhjySync);
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getBmSyncFlag, BoolEnum.TRUE.getType())
                            .set(EduJhjySync::getBmSyncRemark, "上传报名成功");
                    eduJhjySyncService.update(updateWrapper);
                } else {
                    throw new AppException(vo.getAreaCode() + "未找到处理报名保存的个性化方法");
                }
            } catch (AppException e) {
                String msg = e.getMsg();
                if (msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getBmSyncFlag, "2")
                        .set(EduJhjySync::getBmSyncRemark, msg);
                eduJhjySyncService.update(updateWrapper);
            } catch (InvocationTargetException e) {
                try {
                    AppException exception = (AppException) e.getTargetException();
                    String msg = exception.getMsg();
                    if (msg.length() > 300) {
                        msg = msg.substring(0, 200);
                    }
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getBmSyncFlag, "2")
                            .set(EduJhjySync::getBmSyncRemark, msg);
                    eduJhjySyncService.update(updateWrapper);
                } catch (Exception ex) {
                    String msg = ex.getMessage();
                    if (msg.length() > 300) {
                        msg = msg.substring(0, 200);
                    }
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getBmSyncFlag, "2")
                            .set(EduJhjySync::getBmSyncRemark, msg);
                    eduJhjySyncService.update(updateWrapper);
                }

            } catch (Exception e) {
                String msg = e.getMessage();
                if (msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getBmSyncFlag, "2")
                        .set(EduJhjySync::getBmSyncRemark, msg);
                eduJhjySyncService.update(updateWrapper);
            }


        }
        return pageInfo.getSize();
    }

    @Override
    public int eduJhjyBmqxSync(AreaControlVO vo) {
        if (StringUtils.isBlank(vo.getAreaCode())) {
            throw new AppException("行政区划不能为空");
        }
        QueryWrapper<EduJhjySync> querySyncQueryWrapper = new QueryWrapper<>();
        Integer year = eduHelper.thisYear();
        querySyncQueryWrapper.lambda().eq(EduJhjySync::getBmSyncFlag, BoolEnum.TRUE.getType())
                .eq(EduJhjySync::getDeleteSyncFlag, BoolEnum.FALSE.getType())
                .eq(EduJhjySync::getAreaCode, vo.getAreaCode())
                .eq(EduJhjySync::getDeleteFlag, BoolEnum.TRUE.getType())
                .isNotNull(EduJhjySync::getDeleteReason)
                .eq(EduJhjySync::getYear, year);
        PageHelper.startPage(1, 10000);
        List<EduJhjySync> querySyncList = eduJhjySyncService.list(querySyncQueryWrapper);
        PageInfo<EduJhjySync> pageInfo = new PageInfo(querySyncList);
        if (CollectionUtils.isEmpty(querySyncList)) {
            return 0;
        }
        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setEduConfigKey("unifiedSupervisionEnrollDelete");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (apiModel == null) {
            throw new AppException(vo.getAreaCode() + "未找到处理删除取消报名的个性化方法");
        }
        for (EduJhjySync eduJhjySync : pageInfo.getList()) {
            try {
                Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                if (null != bean) {
                    apiModel.getMethod().invoke(bean, eduJhjySync);
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getDeleteSyncFlag, BoolEnum.TRUE.getType())
                            .set(EduJhjySync::getDeleteSyncRemark, "取消报名成功");
                    eduJhjySyncService.update(updateWrapper);
                } else {
                    throw new AppException(vo.getAreaCode() + "未找到处理删除取消报名的个性化方法");
                }
            } catch (AppException e) {
                String msg = e.getMsg();
                if (msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getDeleteSyncFlag, "2")
                        .set(EduJhjySync::getDeleteSyncRemark, msg);
                eduJhjySyncService.update(updateWrapper);
            } catch (InvocationTargetException e) {
                try {
                    AppException exception = (AppException) e.getTargetException();
                    String msg = exception.getMsg();
                    if (msg.length() > 300) {
                        msg = msg.substring(0, 200);
                    }
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getDeleteSyncFlag, "2")
                            .set(EduJhjySync::getDeleteSyncRemark, msg);
                    eduJhjySyncService.update(updateWrapper);
                } catch (Exception ex) {
                    String msg = ex.getMessage();
                    if (msg.length() > 300) {
                        msg = msg.substring(0, 200);
                    }
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getDeleteSyncFlag, "2")
                            .set(EduJhjySync::getDeleteSyncRemark, msg);
                    eduJhjySyncService.update(updateWrapper);
                }

            } catch (Exception e) {
                String msg = e.getMessage();
                if (msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getDeleteSyncFlag, "2")
                        .set(EduJhjySync::getDeleteSyncRemark, msg);
                eduJhjySyncService.update(updateWrapper);
            }
        }
        return pageInfo.getSize();
    }

    @Override
    public int eduJhjyLqSync(AreaControlVO vo) {
        if (StringUtils.isBlank(vo.getAreaCode())) {
            throw new AppException("行政区划不能为空");
        }
        QueryWrapper<EduJhjySync> querySyncQueryWrapper = new QueryWrapper<>();
        Integer year = eduHelper.thisYear();
        querySyncQueryWrapper.lambda().eq(EduJhjySync::getBmSyncFlag, BoolEnum.TRUE.getType())
                .eq(EduJhjySync::getLqFlag, BoolEnum.TRUE.getType())
                .eq(EduJhjySync::getAreaCode, vo.getAreaCode())
                .eq(EduJhjySync::getDeleteFlag, BoolEnum.FALSE.getType())
                .eq(EduJhjySync::getQxlqFlag, BoolEnum.FALSE.getType())
                .eq(EduJhjySync::getLqSyncFlag, BoolEnum.FALSE.getType())
                .eq(EduJhjySync::getYear, year);
        PageHelper.startPage(1, 10000);
        List<EduJhjySync> querySyncList = eduJhjySyncService.list(querySyncQueryWrapper);
        PageInfo<EduJhjySync> pageInfo = new PageInfo(querySyncList);
        if (CollectionUtils.isEmpty(querySyncList)) {
            return 0;
        }
        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setEduConfigKey("unifiedSupervisionEnrollAdmit");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (apiModel == null) {
            throw new AppException(vo.getAreaCode() + "未找到处理录取上传个性化方法");
        }
        for (EduJhjySync eduJhjySync : pageInfo.getList()) {
            try {
                Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                if (null != bean) {
                    apiModel.getMethod().invoke(bean, eduJhjySync);
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getLqSyncFlag, BoolEnum.TRUE.getType())
                            .set(EduJhjySync::getLqSyncRemark, "录取上传成功");
                    eduJhjySyncService.update(updateWrapper);
                } else {
                    throw new AppException(vo.getAreaCode() + "未找到处理录取上传的个性化方法");
                }
            } catch (AppException e) {
                String msg = e.getMsg();
                if (msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getLqSyncFlag, "2")
                        .set(EduJhjySync::getLqSyncRemark, msg);
                eduJhjySyncService.update(updateWrapper);
            } catch (InvocationTargetException e) {
                try {
                    AppException exception = (AppException) e.getTargetException();
                    String msg = exception.getMsg();
                    if (msg.length() > 300) {
                        msg = msg.substring(0, 200);
                    }
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getLqSyncFlag, "2")
                            .set(EduJhjySync::getLqSyncRemark, msg);
                    eduJhjySyncService.update(updateWrapper);
                } catch (Exception ex) {
                    String msg = ex.getMessage();
                    if (msg.length() > 300) {
                        msg = msg.substring(0, 200);
                    }
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getLqSyncFlag, "2")
                            .set(EduJhjySync::getLqSyncRemark, msg);
                    eduJhjySyncService.update(updateWrapper);
                }

            } catch (Exception e) {
                String msg = e.getMessage();
                if (msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getLqSyncFlag, "2")
                        .set(EduJhjySync::getLqSyncRemark, msg);
                eduJhjySyncService.update(updateWrapper);
            }
        }
        return pageInfo.getSize();
    }

    @Override
    public int eduJhjyLqQxSync(AreaControlVO vo) {
        if (StringUtils.isBlank(vo.getAreaCode())) {
            throw new AppException("行政区划不能为空");
        }
        QueryWrapper<EduJhjySync> querySyncQueryWrapper = new QueryWrapper<>();
        int year = eduHelper.thisYear();
        querySyncQueryWrapper.lambda().eq(EduJhjySync::getBmSyncFlag, BoolEnum.TRUE.getType())
                .eq(EduJhjySync::getLqFlag, BoolEnum.TRUE.getType())
                .eq(EduJhjySync::getAreaCode, vo.getAreaCode())
                .eq(EduJhjySync::getLqSyncFlag, BoolEnum.TRUE.getType())
                .eq(EduJhjySync::getDeleteFlag, BoolEnum.FALSE.getType())
                .eq(EduJhjySync::getQxlqFlag, BoolEnum.TRUE.getType())
                .eq(EduJhjySync::getQxlqSyncFlag, BoolEnum.FALSE.getType())
                .eq(EduJhjySync::getYear, year);
        List<EduJhjySync> querySyncList = eduJhjySyncService.list(querySyncQueryWrapper);
        PageInfo<EduJhjySync> pageInfo = new PageInfo(querySyncList);
        if (CollectionUtils.isEmpty(querySyncList)) {
            return 0;
        }
        EduSystemConfigFuncQueryVO queryVO = new EduSystemConfigFuncQueryVO();
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setEduConfigKey("unifiedSupervisionEnrollCancelAdmit");
        String funcCode = eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel = apiContainer.get(funcCode);
        if (apiModel == null) {
            throw new AppException(vo.getAreaCode() + "未找到处理取消录取个性化方法");
        }
        for (EduJhjySync eduJhjySync : pageInfo.getList()) {
            try {
                Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                if (null != bean) {
                    apiModel.getMethod().invoke(bean, eduJhjySync);
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getQxlqSyncFlag, BoolEnum.TRUE.getType())
                            .set(EduJhjySync::getLqFlag, BoolEnum.FALSE.getType())
                            .set(EduJhjySync::getLqSyncFlag, BoolEnum.FALSE.getType())
                            .set(EduJhjySync::getQxlqSyncRemark, "取消录取成功");
                    eduJhjySyncService.update(updateWrapper);
                } else {
                    throw new AppException(vo.getAreaCode() + "未找到处理取消录取的个性化方法");
                }
            } catch (AppException e) {
                String msg = e.getMsg();
                if (msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getQxlqSyncFlag, "2")
                        .set(EduJhjySync::getQxlqSyncRemark, msg);
                eduJhjySyncService.update(updateWrapper);
            } catch (InvocationTargetException e) {
                try {
                    AppException exception = (AppException) e.getTargetException();
                    String msg = exception.getMsg();
                    if (msg.length() > 300) {
                        msg = msg.substring(0, 200);
                    }
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getQxlqSyncFlag, "2")
                            .set(EduJhjySync::getQxlqSyncRemark, msg);
                    eduJhjySyncService.update(updateWrapper);
                } catch (Exception ex) {
                    String msg = ex.getMessage();
                    if (msg.length() > 300) {
                        msg = msg.substring(0, 200);
                    }
                    UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                            .set(EduJhjySync::getQxlqSyncFlag, "2")
                            .set(EduJhjySync::getQxlqSyncRemark, msg);
                    eduJhjySyncService.update(updateWrapper);
                }

            } catch (Exception e) {
                String msg = e.getMessage();
                if (msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduJhjySync> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduJhjySync::getJhjyId, eduJhjySync.getJhjyId())
                        .set(EduJhjySync::getQxlqSyncFlag, "2")
                        .set(EduJhjySync::getQxlqSyncRemark, msg);
                eduJhjySyncService.update(updateWrapper);
            }

        }
        return pageInfo.getSize();
    }


}
